﻿/*
 * 创建人:lf
 * 创建时间:2021/5/21 15:06:10
 * 描述:材料库 
 * */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Furion.DatabaseAccessor;
using Furion.DependencyInjection;

using Mapster;

using Microsoft.EntityFrameworkCore;

using Purchasing.Application.Dtos;
using Purchasing.Core;

namespace Purchasing.Application.Services
{
    public interface IMaterialLibraryService
    {
        Task<List<TopMaterialLibraryDto>> GetTopListAsync(int topCount);
    }

    public class MaterialLibraryService: IMaterialLibraryService, ITransient
    {
        private readonly IRepository<UfMaterialLibrary> _repository;

        public MaterialLibraryService(IRepository<UfMaterialLibrary> repository)
        {
            this._repository = repository;
        }

        public async Task<List<TopMaterialLibraryDto>> GetTopListAsync(int topCount)
        {
            var entity = await _repository.AsQueryable().Take(topCount).ToListAsync(); 
            return entity.Adapt<List<TopMaterialLibraryDto>>();
        }
    }
}
